<?php 
/**
 * eBay Label Printing Program Country List Database Table Class 
 * This is a Db Table Class , It stores Country List
 * @package  eBayLabelPrinter
 * @category Models/DbTable
 * @author   Norman Dong <norman.dong@hotmail.com>
 * @version  Initial
 * @copyright LeadCasket.com
 * @link     www.leadcasket.com
 * @license  Commercial
 */
 class Model_DbTable_Assist_Countrylist extends Zend_Db_Table_Abstract 
{
	/**
	 * @var string Class Table Name
	 */
	protected $_name = 'assist_country_list'; 
	
	/**
	 * List Country Function
	 * get all country list from the Database , id and name 
	 * @return array  idcountry and name country two diemontal array
	 */
	public function listCountry(){
		$rows = $this->fetchAll('1');
		return $rows->toArray();
	}

	/**
	 * Get country array by Id
	 * @param int $idCountry
	 * @return array  
	 */
	public function getCountry($idCountry){
		
		$idCountry = (int) $idCountry;
		$row = $this->fetchRow('`id_country` = '.$idCountry);
		if(!$row){
			return false;
		}
		return $row->toArray();		
		
	}
	
	/**
	 * Get country Name by Id
	 * @param int $idCountry
	 * @return array
	 */
	public function getCountryName($idCountry){
	
		$idCountry = (int) $idCountry;
		$row = $this->fetchRow('`id_country` = '.$idCountry);
		if(!$row){
			return false;
		}
		$arrRow = $row->toArray();		
		return $arrRow['name_country'];
	
	}
		
	/**
	 * Search Country Array by Name 
	 * @param string $countryName 
	 * @return array 
	 */
	public function searchCountryList($countryName){
		$select = $this->_db ->select()
		-> from ($this->_name,array('name_country'))
		-> where('`name_country` LIKE ?', "%".$countryName."%")
		-> limit(5);
		$result = $this->getAdapter()->fetchAll($select);
		return $result;
	}
			
	/**
	 * Search Country ID by Name
	 * @param string $countryName
	 * @return array
	 * @todo Not decide it necessary
	 */
	public function searchCountryId($countryName){
		$select = $this->_db ->select()
		-> from ($this->_name,array('name_country'))
		-> where('`name_country` LIKE ?', "%".$countryName."%")
		-> limit(5);
		$result = $this->getAdapter()->fetchAll($select);
		return $result;
	}				
}
?>